package com.jgssp.ad.sdk.mediation.adapter;

import android.content.Context;
import android.util.Log;

import com.bytedance.sdk.openadsdk.mediation.bridge.custom.MediationCustomInitLoader;
import com.bytedance.sdk.openadsdk.mediation.custom.MediationCustomInitConfig;
import com.jgssp.ad.sdk.mediation.utils.ThreadUtils;

import java.util.Map;

import cn.jiguang.jgssp.ADJgSdk;
import cn.jiguang.jgssp.config.ADJgInitConfig;
import cn.jiguang.jgssp.config.CustomDeviceInfoController;
import cn.jiguang.jgssp.listener.ADJgInitListener;

/**
 * @Description: JgSSP 初始化Config
 */
public class CustomerAdapterConfig extends MediationCustomInitLoader {

    private static final String TAG = Const.TAG + "_" + CustomerAdapterConfig.class.getSimpleName();

    private String getOaid() {
        //TODO 补充获取oaid具体方法，否则会影响广告收益
        return null;
    }

    private String getVaid() {
        //TODO 补充获取vaid具体方法
        return null;
    }

    @Override
    public void initializeADN(final Context context, final MediationCustomInitConfig customInitConfig, Map<String, Object> map) {
        //注意！！ 自定义Adapter初始化ADN在子线程中 ，需要切换主线程中进行极光AdsSDK初始化
        ThreadUtils.runOnUIThread(new Runnable() {
            @Override
            public void run() {
                ADJgInitConfig initConfig = new ADJgInitConfig.Builder()
                        .appId(customInitConfig.getAppId())
                        .debug(BuildConfig.DEBUG)
                        //【慎改】是否同意隐私政策，将禁用一切设备信息读起严重影响收益
                        .agreePrivacyStrategy(true)
                        .isCanUseLocation(true)
                        .isCanUsePhoneState(true)
                        .setCustomDeviceInfoController(new CustomDeviceInfoController() {
                            @Override
                            public String getOaid() {
                                return CustomerAdapterConfig.this.getOaid();
                            }

                            @Override
                            public String getVaid() {
                                return CustomerAdapterConfig.this.getVaid();
                            }
                        })
                        .build();

                ADJgSdk.getInstance().init(context, initConfig, new ADJgInitListener() {
                    @Override
                    public void onSuccess() {
                        Log.i(TAG, "极光SSP初始化成功" + Thread.currentThread().getName());
                    }

                    @Override
                    public void onFailed(String s) {
                        Log.i(TAG, "极光SSP初始化失败" + Thread.currentThread().getName());
                    }
                });
            }
        });

    }

    @Override
    public String getNetworkSdkVersion() {
        return ADJgSdk.getInstance().getSdkVersion();
    }

}
